/**
 * @file models/performance.js
 * @author
 */
import { routerRedux } from 'dva/router';
import api from '../api';
import moment from 'moment'


export default {
	namespace: 'performance',
	state: {
		beginDate:'',
		endDate:'',
		jobName:'',
		currentpage:0,
		pagesize:0
	},
	subscriptions : {
		setup({dispatch, history}) {
			history.listen(({ pathname, query }) => {
				// 没有参数时，向后端请求数据，并且改变query
				if( pathname === '/report/performance' ){
					dispatch({type: 'whetherRequest',payload:query,pathname})
				}
			})
		}
	},
	effects : {

		* whetherRequest({
				payload,pathname
			}, { put,select}) {
				yield put({
					type:'query',
					payload
				})
		},
		* query({payload}, {call, put,select}){
			// console.log(`query event`);
		},
		* changeRouter({payload}, {put}){
			yield put(routerRedux.push(payload))
		}

	},
	reducers : {
		setState(state, {payload}) {
			return {
				...state,
				...payload
			}
		},
		clearState(state) {
			const {
				...other
			}=state
      return{
				...other
			}
    },
	}
};
